package cn.com.twoke.easyproject.aspect.request.lock.hook.proceed;

import cn.com.twoke.easyproject.aspect.request.lock.RequestLock;
import cn.com.twoke.easyproject.aspect.request.lock.RequestLockKeyCacheManager;
import cn.com.twoke.easyproject.common.utils.ExceptionUtils;
import lombok.RequiredArgsConstructor;
import org.aspectj.lang.ProceedingJoinPoint;

@RequiredArgsConstructor
public class NormalJoinPointProceed implements RequestLockKeyJoinPointProceed {

    private final RequestLockKeyCacheManager cacheManager;

    @Override
    public Object proceed(String key, RequestLock requestLock, ProceedingJoinPoint joinPoint) throws Throwable {
        // 校验请求是否被锁定
        if (cacheManager.has(key, requestLock)) {
            ExceptionUtils.throwBusinessException(requestLock.message());
        }
        return joinPoint.proceed();
    }

}
